<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>03监视属性-立即监视</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
        <style>
            img{
                width:100px;
            }
        </style>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo">
           <h1>今天天气{{info}}</h1>
           <button @click="weather">查看天气</button>
           <img :src="url">
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        new Vue({
            el:'#demo',
            data:{
                isHot:true,
                url:''
            },
            methods:{
                weather(){
                    this.isHot = !this.isHot;
                }
            },
            computed:{
                info(){
                    return this.isHot ? '炎热' : '凉爽'
                }
            },
            watch:{
                isHot:{
                    immediate:true,
                    handler(newValue){
                        if(newValue) this.url = 'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
                        else this.url = 'https://s3.ax1x.com/2020/12/13/reCaqg.jpg'
                    }
                }
            }
        })
    </script>
</html>